EXTLIB=../ocaml/extlib-dev
SWFLIB=../ocaml/swflib
EXTC=../ocaml/extc
HXJVM=../haxejvm
NEKO=../neko
XML=../ocaml/xml-light
LIBS_SRC=$(EXTLIB)/*.ml* $(SWFLIB)/*.ml* $(EXTC)/extc.ml* $(XML)/*.ml*
SRC=$(NEKO)/libs/include/ocaml/*.ml* *.ml* $(HXJVM)/*.ml*
LIBS=unix.cma str.cma
FLAGS=-o haxe -pp camlp4o -P $(XML)/dtd.mli -lp "-custom -cclib extc_stubs.o -cclib -lz xml_parser.cmo xml_lexer.cmo dtd.cmo xmlParser.cmo xml.cmo "
LFLAGS=



ifeq ($(PPC),1)
LFLAGS=-ccopt '-arch ppc'
endif

all:
	ocamlc $(LFLAGS) -c $(EXTC)/extc_stubs.c
	ocamake -lp "$(LFLAGS)"  $(FLAGS) $(LIBS_SRC) $(SRC) $(LIBS) -g 

mode_ppc:
	sudo ln -sfh /usr/local/bin/ocamlopt.ppc /usr/local/bin/ocamlopt
	sudo ln -sfh /usr/local/lib/ocaml_ppc /usr/local/lib/ocaml

mode_intel:
	sudo ln -sfh /usr/local/bin/ocamlopt.intel /usr/local/bin/ocamlopt
	sudo ln -sfh /usr/local/lib/ocaml_intel /usr/local/lib/ocaml

universal:
	make PPC=1 clean mode_ppc all
	mv haxe haxe.ppc
	make clean mode_intel all
	mv haxe haxe.intel
	lipo -create -arch i386 haxe.intel -arch ppc haxe.ppc -output haxe
	chmod +x haxe

tools:
	(cd std/tools/haxedoc && haxe haxedoc.hxml && cp haxedoc ../../..)
	(cd std/tools/haxelib && haxe haxelib.hxml && cp haxelib ../../..)

clean:
	rm -f extc_stubs.o
	ocamake $(FLAGS) -clean $(LIBS_SRC) $(SRC) $(LIBS)
